import formJs from "./regexDetail.js"; //新增弹框配置项
import myCharts from "@/components/intelligentMaintenanceManage/temperatureHumidity/echarts.vue";
import TableData from "@/components/public/el-table-pagination"; //主页面列表
//主页面列表
import publicForm from "@/components/commonPublic/fromCom.vue"; //弹框form
import {
    getWs08HygsMonitordataByFid, //详情
    getWs08HygsMonitordataByFids,
} from "@/api/request.js";
export default {
    props: [
        "dialogVisible",
        "dialogTitle",
        "statusNum",
        "currentRow",
        "fCompanyid",
        "fCompanyname"
    ],
    data() {
        return {
            visible: "",
            loadings: false,
            title: null,
            isLock: false,
            loading: false,
            tableData: [],
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            queryCriteriaData: {}, //分页
            dialogHeight: null,
            activeIndex: "1",
            formObj: formJs.formObj,
            additionalObj: formJs.additionalObj,
            isEdit: false,
            currntData: null,
            dataInfo: null,
            startDates: null,
            treeData: [], //材料种类
            getList: {
                taskNumber: "", //该数据的设备编号(必传)
                startDates: "", //开始时间(必传) 精确到秒  一般传当前时间的前40分钟
                endDates: "", //结束时间(必传）一般传当前时间的前40分钟
                page: 1, //当前页码
                pageSize: 15, //每页显示条数
                timeDates: null
            },
            formData: {
                fId: "", //必传
                userId: "", //当前登录人id
                userName: "", //当前登录人姓名
                recordfiles: [], //删除文件id集合
                fCommissiondates: this.common.day(0), //委托日期
                fCommissionname: "", //委托人
                fCommissionid: "", //委托人id
                fUnitname: "", //接收委托单位名称
                fUnitid: "", //接收委托单位id
                fOrdernumber: "", //委托单号
                fFileurl: "", //委托单附件
                fNote: "" //备注
            },
            formDatafileList: [], //工作计划资料
            btnShow: true,
            currentDetail: null,
            selectPostionObj: [],
            types: [],
            // 材料弹框
            materialRow: {},
            typeData: [{
                    text: "实时数据",
                    show: true
                },
                {
                    text: "列表数据",
                    show: false
                },
            ],
            chartsData: null,
            fCompanynames: null,
            fCompanyids: null,
            fFileurllist: [], //附件
        };
    },
    components: {
        publicForm,
        myCharts,
        TableData
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        statusNum: {
            handler(newVal) {
                if (newVal) {
                    this.edit(newVal);
                }
            },
            immediate: true,
        },

        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentDetail = newVal;
                    this.getList.taskNumber = newVal.fDeviceencode
                    this.getList.startDates = this.common.day(0) + " " + "00:00:00"
                    this.getList.endDates = this.common.day(0) + " " + "23:59:59"
                    this.getList.timeDates = this.common.day(0)
                    this.getDetail(this.getList)
                    this.getDetail1(this.getList)
                }
            },
            immediate: true,
        },
        fCompanyid: {
            handler(newVal) {
                if (newVal) {
                    this.fCompanyids = newVal
                }
            },
            immediate: true,
        },
        fCompanyname: {
            handler(newVal) {
                if (newVal) {
                    this.fCompanynames = newVal
                }
            },
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("monitorBack-userInfo"));
        this.btnShow = true
        if (this.statusNum == 7) { //查看
            this.btnShow = false
            this.formObj.map((item) => {
                item.disabled = true;
            });
        }
        this.getHeight();
    },
    methods: {
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },
        handleSelect(key) {
            this.activeIndex = key;
        },
        closeDialog() {
            this.$emit("close");
        },
        changeType(e, index) {
            for (let i in this.typeData) {
                if (parseFloat(i) === index) {
                    this.typeData[i].show = true;
                } else {
                    this.typeData[i].show = false;
                }
            }
        },
        edit() {
            this.formData = this.$options.data.call(this).formData;
        },
        getDetail1(obj) {
            var data = {
                taskNumber: obj.taskNumber, //该数据的设备编号(必传)
                startDates: obj.startDates, //开始时间(必传) 精确到秒  一般传当前时间的前40分钟
                endDates: obj.endDates, //结束时间(必传）一般传当前时间的前40分钟
            }
            this.loading = true;
            getWs08HygsMonitordataByFids(data).then((res) => {
                if (res.errcode == 0) {
                    this.loading = false;
                    var data = res.data
                    this.chartsData = data
                    this.loadings = false

                }
            });
        },
        // 详情
        getDetail(obj) {
            getWs08HygsMonitordataByFid(obj).then((res) => {
                if (res.errcode == 0) {
                    var data = res.data.pageInfo.list
                    this.tableData = data
                    this.queryCriteriaData = res.data.pageInfo;
                }else {
                    this.loading=false;
                    this.$message.error(res.msg);
                }
            });
        },
        selectTime(e) {
            this.loadings = true
            if (e) {
                this.getList.startDates = e + " " + "00:00:00"; // 开始时间
                this.getList.endDates = e + " " + "23:59:59"; // 截至时间
            } else {
                this.getList.startDates = ""; // 开始时间
                this.getList.endDates = ""; // 截至时间
            }
            this.getList.timeDates = e
            this.getDetail(this.getList);
            this.getDetail1(this.getList);
        },
    },
};